package com.gwall.test.plateform.config;

import com.gwm.open.sdk.ClientConfig;
import com.gwm.open.sdk.OpenClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * 开放平台根据工号获取员工信息的接口配置
 * 开放平台文档连接:
 * <a href="https://open.gwm.cn/helpWord?wordId=a6a41d00072a4a2e8a15e15c539f0796&titleId=67e372607cd6446a94f7fa5202493387&name=%E4%BA%BA%E5%91%98%E4%BF%A1%E6%81%AF%E6%9C%8D%E5%8A%A1">...</a>
 */
@Component
@Data
@ConfigurationProperties(prefix = "open.hr")
public class OpenPlatformConfig {

    private String appKey;

    private String secret;

    private String userInfoByStaffNumberUrl;

    private String groupDetailByGroupIdUrl;

    private String parentGroupIdsByGroupIdUrl;

    private String groupListUrl;

    private String empListUrl;

    private OpenPlatformConfig() {};

    // 初始化工具客户端
    private static final Optional<OpenClient> openClientOptional = Optional.empty(); // ;


    public OpenClient getOpenClientInstance() {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setHeaderRequireSign(true);
        return getOpenClientInstance(clientConfig);
    }

    public OpenClient getOpenClientInstance(ClientConfig clientConfig) {
        OpenClient openClient = openClientOptional.orElse(new OpenClient(appKey, secret));
        openClient.setClientConfig(clientConfig);
        return openClient;
    }
}